package com.tengju.support.application.apollo;

import com.tengju.support.domain.service.ApolloOpenApiService;
import com.tengju.user.domain.service.HuaweiObsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.ByteArrayInputStream;

@Service
@Slf4j
public class ChangeWxQrCodeService {
    private final HuaweiObsService obsService;
    private final ApolloOpenApiService apolloOpenApiService;

    public ChangeWxQrCodeService(HuaweiObsService obsService,
                                 ApolloOpenApiService apolloOpenApiService) {
        this.obsService = obsService;
        this.apolloOpenApiService = apolloOpenApiService;
    }

    /**
     * 更改企微二维码
     */
    public void changeQrCode(MultipartFile file) {
        try {
            String fileName = "weChatCompany" + System.currentTimeMillis();
            String fileUrl = obsService.uploadImg(file);
            apolloOpenApiService.saveParam("weChatCompany.qrCodeUrl", fileUrl);
            apolloOpenApiService.publish("企微二维码");
            log.info("修改企微二维码成功，url:{}", fileUrl);
        } catch (Throwable e) {
            log.error("修改企业微信二维码失败", e);
        }


    }
}
